// import  AUTH from '../../../utils/auth'
const app = getApp()
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    TabCur: 0,
    tabNav: ['材料', '做法', '推荐'],
    user:{dianzhan:false,shoucang:false},
    showComment:'none',
  },
  detail(e) {
    console.log(e)
    wx.navigateTo({
      url: '/pages/basics/food/detail?id=' + e.currentTarget.dataset.code
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.globalData.comment_id  = options.id
    wx.request({

      url : "http://" + app.globalData.url + "/cook/detail",
      method: 'GET',
      header: {"jwt": app.globalData.jwt},
      data: {
        "code": options.id,
        "user_id": wx.getStorageSync('user_id')
      },
      success: res => {
        this.data.menuDetailsList = res.data.data;
        console.log("detail", app.globalData.jwt)
        this.setData({
          detail: this.data.menuDetailsList
        });
      }
    }),
    wx.request({
      url : "http://" + app.globalData.url + "/cook/recommend/" + options.id + "/",
      method: 'GET',

      success: res => {
        console.log("reco", res.data)
        this.setData({
          reco: res.data
        });
      }
    }),
    wx.request({
      url : "http://" + app.globalData.url + "/cook/like/" + options.id + "/",
      method: 'GET',
      header: {"jwt": app.globalData.jwt},
      data: {
        "user_id": wx.getStorageSync('user_id')
      },
      success: res => {
this.setData({
    "user.dianzhan": res.data.like,
    "user.shoucang": res.data.collect
})
      }

    })  
  },
  dianZhan: function (options){
    if (this.data.user.dianzhan){
      this.data.user.dianzhan = false,
      this.setData({"user.dianzhan":false,"showComment": "showComment"})

    }else(
      this.data.user.dianzhan = true,
      this.setData({"user.dianzhan":true,"showComment": "showComment"})

    )
      console.log("dianzha_id", app.globalData.comment_id)
    wx.request({
      url : "http://" + app.globalData.url + "/cook/like/" + app.globalData.comment_id + "/",
      method: 'POST',
      data: {
        // 0代表点赞
        "state": "0",
        "jwt": app.globalData.jwt,
        "user_id": wx.getStorageSync('user_id')
      },
      
      success: res => {
        this.data.menuDetailsList = res.data.data;
        wx.showToast({
          title: res.data.msg,
        })
        if (res.data.code == 0){
          this.data.user.dianzhan = true,
          this.setData({"user.dianzhan":true,"showComment": "showComment"})
        }else{
          this.data.user.dianzhan = false,
          this.setData({"user.dianzhan":false,"showComment": "showComment"})
        }
      }
    })  
  },

  shouchang: function(options){
    if (this.data.user.shoucang){
      this.data.user.shoucang = false,
      this.setData({"user.shoucang":false,"showComment": "showComment"})

    }else(
      this.data.user.shoucang = true,
      this.setData({"user.shoucang":true,"showComment": "showComment"})
    )
    wx.request({
      url : "http://" + app.globalData.url + "/cook/like/" + app.globalData.comment_id + "/",
      method: 'POST',
      data: {
        // 1代表收藏
        "state": 1,
        "jwt": app.globalData.jwt,
        "user_id": wx.getStorageSync('user_id')
          },
      
      success: res => {
        this.data.menuDetailsList = res.data.data;
        wx.showToast({
          title: res.data.msg,
        })
        if (res.data.code == 0){
          this.data.user.shoucang = true,
          this.setData({"user.shoucang":true,"showComment": "showComment"})
        }else{
          this.data.user.shoucang = false,
          this.setData({"user.shoucang":false,"showComment": "showComment"})
        }
      }
    })  
  },
  tabSelect(e) {
    console.log(e);
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  // 跳转函数 navigateto
  comment(){
    wx.navigateTo({
      url: '/pages/comment/comment?id='+10,
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})